package mannA1.view;

import java.awt.Canvas;
import java.awt.Graphics;

import mannA1.model.Edge;
import mannA1.model.Model;


/** The canvas where the Lines and Edges will be drawn. */
public class LinesCanvas extends Canvas {
	
	Model m;
	public int[] x;
	
	/** Makes sure the canvas sees the model, sets up the canvas size. */
	public LinesCanvas(Model m)
	{
		super();
		this.m = m;
		this.setSize(401, 201);
		this.x = new int[m.numLines];
	}
	
	/** Paints the lines, and on redraw, paints every edge in the model.  */
	@Override
	public void paint(Graphics g)
	{
		int r = this.m.numLines;
		int s = 300/r;
		
		// r starts at 0!!!  so x[0] through x[r-1]
		while (r > 0)
		{
			g.drawLine(s*r, 1, s*r, 200);
			x[r-1] = s*r;
	
			r--;
		}
		
		for (int i = 0; i < m.edges.size(); i++)
		{
			g.drawLine(x[m.edges.get(i).leftChoice], m.edges.get(i).height, x[m.edges.get(i).rightChoice], m.edges.get(i).height);
		}	
	}
}
